<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html >
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>入库</title>
    <link rel="stylesheet" type="text/css"
          href="easyui/themes/bootstrap/easyui.css">
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
    <script type="text/javascript" src="myjs/path.js"></script>
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
    <script src="js/yangshi.js"></script>
    <script type="text/javascript" src="myjs/ruku.js"></script>
</head>
<body>
<shiro:lacksPermission name="ruku:look">没有操作此模块权限。。。</shiro:lacksPermission>
<shiro:hasPermission name="ruku:look">
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north',split:true,border:false"
         style="height: 60%; width: 100%">
        <div id="tb" style="padding: 5px; height: auto">
            <div style="margin-bottom: 5px">
                <shiro:hasPermission name="ruku:create">
                    <a id='xinzeng' href="#" class="easyui-linkbutton"
                       iconCls="icon-add" plain="true" onclick="winOpen(0)">新增单</a>
                </shiro:hasPermission>
                <shiro:hasPermission name="ruku:update">
                    <a id='xiugai' href="javascript:void(0)" class="easyui-linkbutton"
                       data-options="iconCls:'icon-edit',plain:true" onclick="winOpen(1)">修改单</a>
                </shiro:hasPermission>
                <shiro:hasPermission name="ruku:del">
                    <a id='shachu' href="javascript:void(0)" class="easyui-linkbutton"
                       data-options="iconCls:'icon-remove',plain:true" onclick="shanchu()">删除单</a>
                </shiro:hasPermission>

                <shiro:hasPermission name="ruku:tijiao">
                    <a href="#" id="shenhe" class="easyui-linkbutton"
                       iconCls="icon-ok" plain="true" onclick="tijiao()">提交</a>
                </shiro:hasPermission>
                <shiro:hasPermission name="ruku:ruku">
                    <a href="#" id="rukuspan" class="easyui-linkbutton"
                       iconCls="icon-redo" plain="true" onclick="ruku()">入库<span
                            id="sts"></span></a>
                </shiro:hasPermission>
                <shiro:hasPermission name="ruku:bohui">
                    <a href="#" id="shenhe2" class="easyui-linkbutton"
                       iconCls="icon-undo" plain="true" onclick="bohui()">驳回</a>
                </shiro:hasPermission>

                <shiro:hasPermission name="ruku:chexiao">
                    <%-- <a href="#" id="shenhe2" class="easyui-linkbutton"
                        iconCls="icon-undo" plain="true" >撤销</a>--%>
                </shiro:hasPermission>
            </div>
            <div>
                制单日期从: <input id="startTime" class="easyui-datebox" editable='false'
                              style="width: 120px"> 到: <input id="endTime"
                                                              class="easyui-datebox" editable='false'
                                                              style="width: 120px">
                <a
                        href="javascript:void(0)" class="easyui-linkbutton"
                        data-options="iconCls:'icon-reload',plain:true"
                        onclick="congzhi()">重置搜索</a>
                机构类型：
                <input id="tree" class="easyui-combotree"
                       style="width: 160px;"/>
                入库方式:<input id="search" style="width: 200px" class="easyui-searchbox"
                            data-options="searcher:qq,menu:'#mm',prompt:'输入单号进行搜索'">
                <script type="text/javascript">
                    function congzhi() {
                        $('#startTime').combo('setText', '');
                        $('#endTime').combo('setText', '');
                        $('#startTime').combo('setValue', '');
                        $('#endTime').combo('setValue', '');
                        load();
                    }
                    function qq(value, name) {
                        //value是搜索框里的值,name是选择框里的值
                        load();
                    }

                </script>
                <div id="mm">
                    <div data-options="name:'-1'">全部</div>
                    <div data-options="name:'0'">自产入库</div>
                    <div data-options="name:'1'">进货入库</div>
                    <div id="cp" data-options="name:'3'">次品入库</div>
                </div>

                <label><input type='checkbox' id='caogao'
                              onclick='load()' checked='checked' value="0">查看草稿</label> <label><input
                    type='checkbox'
                    value="1"
                    id='dairuku'
                    onclick='load()'
                    checked='checked'><span>查看待入库</span>
            </label> <label><input id='yiruku' type='checkbox'
                                   onclick='load()' value="2"><span>查看入库</span></label>
            </div>

        </div>
        <table id="dg">

        </table>
    </div>
    <div data-options="region:'center',border:false"
         style="height: 40%; width: 100%">
        <div id="tbb" style="padding: 5px; height: auto">
            <span>详细信息 | </span> <label><input type='radio'
                                               onclick='loadChildren()' name="fenlei" class='fenlei'
                                               value='2'><span>按尺码</span></label>
            <label><input
                    type='radio' onclick='loadChildren()' class='fenlei' name="fenlei"
                    value='1'><span>按颜色</span></label>
            <label><input type='radio' onclick='loadChildren()'
                          checked='checked' class='fenlei' name="fenlei" value='0'>按款号</label>
        </div>
        <table id="dgChildren">

        </table>
    </div>

    <div id="windowadd" class="easyui-dialog"
         data-options="buttons:'#bb',modal:true,closed:true,iconCls:'icon-save',maximizable:false,minimizable:false,closable: false,collapsible:false"
         style="width: 65%; height: 70%; min-height: 480px; min-width: 1040px">
        <table style="width: 100%; margin: 0 auto; margin-bottom: 15px; padding-bottom: 7px;">
            <tr>
                <th colspan="6" style="text-align: center"><h2>入 库 单</h2></th>
            </tr>
            <input id='id' type='hidden'>
            <tr>
                <td align="right">入库单号:</td>
                <td align="center"><input class="easyui-textbox" id="rukudanhao" readonly="true" style="width:150px">
                </td>
                <td align="center">入库类型:</td>
                <td align="left"><span title="注:切换入库类型将清空已编辑内容!" class="easyui-tooltip"
                                       data-options="position: 'top'">
                    <select id="leixing"
                            class="easyui-combobox"
                            data-options="panelHeight:'auto',editable : false"
                            style="width: 150px; height: 25px">
                        <option value="0">自产</option>
                        <option value="1">进货</option>
                        <option value="3">次品</option>
                    </select></span></td>
            </tr>
            <tr id="all">
                <td align="right">供应商:<span style="color:red">*</span></td>
                <td align="center"><input id="gongyingshang" class="easyui-combobox"/> <input id="gys"
                                                                                              class="easyui-combotree"
                                                                                              style="width: 150px;"/>
                </td>
                <td align="center"><span id="caijiankuanhao">裁剪款号：</span>
                </td>
                <td align="left"><input id="caijiandan" style="width: 150px">
                </td>
            </tr>
        </table>
        <div style="height: 20px;"></div>

        <div style="height: auto" id="tb1">
            商品款号：<select id="se" class="easyui-combobox"
                         style="width: 140px;"></select>
            <select id="jinghuo" class="easyui-combobox"
                    style="width: 140px;"></select>
            <select id="cc" style=" margin-left:50px; width: 140px;"></select>
            <div id="sp"></div>
            <script type="text/javascript">

                $(document).keyup(function (event) {
                    if (event.shiftKey && event.keyCode == 13) {
                        accept()
                    }

                    if (event.ctrlKey && event.keyCode == 13) {
                        $('#save').trigger('click')
                    }
                })

                function diaoyong(tar) {
                    if (event.shiftKey) {
                        $(tar).parents('tr').next().find('input').eq(0).blur();
                        return
                    }
                    if (event.keyCode == 13) {
                        if (flg) {
                            //取到当前填写的数
                            var shuliang = $(tar).val() - 0;
                            //数量
                            var count = $(tar).parents('td').siblings('td').find('input').length
                            for (var i = 0; i < count - 1; i++) {
                                $(tar).parents('td').siblings('td').find('input').eq(i).val(shuliang)
                            }
                            $(tar).parents('td').siblings('td').find('input').eq(count - 1).val(shuliang * count)
                            $(tar).parents('tr').next().find('input').eq(0).focus();
                            //只有自产才有成本价
                            if ($("#leixing").combobox("getValue") == 1) {
                                if ($(tar).parents('tr').next().html() == null || $(tar).parents('tr').next().html() == "") {
                                    $('#chengbenjia').numberbox().next('span').find('input').focus();
                                    return;
                                }
                            }
                            if ($("#leixing").combobox("getValue") == 0 && $("#jgid").val() != 1) {
                                if ($(tar).parents('tr').next().html() == null || $(tar).parents('tr').next().html() == "") {
                                    $('#chengbenjia').numberbox().next('span').find('input').focus();
                                }
                            }

                        }
                        flg = true
                    }
                }
                //小计
                function diaoyong1(tar) {
                    if (event.shiftKey) {
                        $(tar).parents('tr').next().find('input').eq(0).blur();
                        return
                    }
                    if (event.keyCode == 13) {
                        if (flg) {
                            var count = $(tar).parents('td').siblings('td').find('input').length
                            var zongji = $(tar).val() - 0;
                            //得到这个数量
                            var sl = zongji / count
                            for (var i = 0; i < count; i++) {
                                $(tar).parents('td').siblings('td').find('input').eq(i).val(sl);
                            }
                            $(tar).parents('tr').next().find('input').eq(count).focus();
                            if ($("#leixing").combobox("getValue") == 1) {
                                if ($(tar).parents('tr').next().html() == null || $(tar).parents('tr').next().html() == "") {
                                    $('#chengbenjia').numberbox().next('span').find('input').focus();
                                }
                            }
                        }
                        flg = true
                    }
                }
                var iq = 1;
                var flg = true;//解决enter键第一次冲突问题
                function A() {
                    var sum = 0;
                    if (iq < $("#sp table tr").length) {
                        var a = $("#sp table").find("tr").eq(iq).find("td").eq(1).children().val()
                        for (var j = 1; j < $("#sp table td").length / $("#sp table tr").length - 1; j++) {
                            /*  var v = $("#sp table tr:eq(0) td:eq(1)") */
                            if (a != '') {
                                if (/^[+]?[1-9]+\d*$/.test(a)) {
                                    $("#sp table").find("tr").eq(iq).find("td").eq(j).children().val(a)

                                } else {
                                    $("#sp table").find("tr").eq(iq).find("td").eq(1).children().focus()
                                    return
                                }
                                sum += parseInt($("#sp table").find("tr").eq(iq).find("td").eq(j).children().val())
                            }
                        }
                        $("#sp table").find("tr").eq(iq).find("td").eq($("#sp table td").length / $("#sp table tr").length - 1).children().val(sum)
                        if (iq == $("#sp table tr").length - 1) {
                            iq = 0
                            $("#sp table").find("tr").eq(1).find("td").eq(1).children().focus()
                        }
                    }
                    $("#sp table").find("tr").eq(iq + 1).find("td").eq(1).children().focus()
                    iq++
                }
                $(function () {
                    $('#cc').combo({
                        editable: false,
                        panelWidth: 500,
                        panelHeight: 240
                    });
                    $('#sp').appendTo($('#cc').combo('panel'));
                });
            </script>


            <span title="按住Shift+Enter进行快捷保存编辑" class="easyui-tooltip"
                  data-options="position: 'top'"><a href="javascript:void(0)"
                                                    class="easyui-linkbutton"
                                                    data-options="iconCls:'icon-save',plain:true" onclick="accept()">保存编辑</a></span>
            <a href="javascript:void(0)" class="easyui-linkbutton"
               data-options="iconCls:'icon-remove',plain:true"
               onclick="removeit()">删除新增</a> <input id="product" class="easyui-searchbox"
                                                    data-options="prompt:'输入款号进行搜索',searcher:doSearch"
                                                    style="width: 130px"></input>
            <script>
                function doSearch(value) {
                    var ii = $('#dgg').datagrid('getRows').length;
                    var j = 0;
                    for (var i = 0; i < ii; i++)
                        if ($('#dgg').datagrid('getData').rows[i].product.indexOf(value) != -1) {
                            $('#dgg')
                                .datagrid(
                                    'insertRow',
                                    {
                                        index: j,
                                        row: {
                                            product: $('#dgg')
                                                .datagrid('getData').rows[i].product,
                                            shuliang: $('#dgg')
                                                .datagrid('getData').rows[i].shuliang,
                                            color: $('#dgg').datagrid(
                                                'getData').rows[i].color,
                                            size: $('#dgg').datagrid(
                                                'getData').rows[i].size,
                                            style: $('#dgg')
                                                .datagrid('getData').rows[i].style,
                                            productName: $('#dgg').datagrid(
                                                'getData').rows[i].productName,
                                            tiepai: $('#dgg')
                                                .datagrid('getData').rows[i].tiepai,
                                            price: $('#dgg')
                                                .datagrid('getData').rows[i].price,
                                            chengbenjia: $('#dgg')
                                                .datagrid('getData').rows[i].chengbenjia,
                                            productionId: $('#dgg')
                                                .datagrid('getData').rows[i].productionId,
                                            id: $('#dgg')
                                                .datagrid('getData').rows[i].id,
                                            kerushuliang: $('#dgg')
                                                .datagrid('getData').rows[i].kerushuliang
                                        }
                                    });
                            $('#dgg').datagrid('deleteRow', i + 1);
                            j++
                        }

                }
            </script>

            <div style="float: right">共<span id="zongjianshu">0</span>件&nbsp;&nbsp;&nbsp;总价：<span id="zongjia">0</span>
            </div>
        </div>
        <table id='dgg' style="height: 370px" class="easyui-datagrid"></table>
        <div id="bb">
					<span title="按住Ctrl+Enter进行快捷保存" class="easyui-tooltip"
                          data-options="position: 'top'"><button id="save"
                                                                 onclick="saveRuku()" class="easyui-linkbutton"
                                                                 data-options="iconCls:'icon-save'">保存</button></span>
            <button onclick="closeWindow()"
                    class="easyui-linkbutton" data-options="iconCls:'icon-no'">取消
            </button>
        </div>
    </div>
    <input id="jgid" value="<%=request.getParameter("jgid")%>">
    </shiro:hasPermission>
    mign
</body>
</html>
<script>
    if ($("#jgid").val() != 1) {
        $("#cp").hide();
    }
    // 查询机构树
    function findTree() {
        //加载combotree
        $.ajax({
            url: path + '/jg/tree.do',
            dataType: 'json',
            success: function (data) {
                if (data.code != 400) {
                    $('#tree').combotree('loadData', data.rows);
                } else {
                    $.messager.alert('提示', data.msg);
                }
            }
        })
        //加载树
        $.ajax({
            url: path + '/jg/tree/all.do',
            dataType: 'json',
            success: function (data) {
                if (data.code != 400) {
                    $('#gys').combotree('loadData', data.rows);
                } else {
                    $.messager.alert('提示', data.msg);
                }
            }
        })
    }

    /*入库上面表格*/
    $("#dg").datagrid({
        method: 'GET',
        striped: true,
        rownumbers: false,
        singleSelect: true,
        toolbar: '#tb',
        checkbox: false,
        fit: true,
        striped: true,
        fitColumns: false,
        autoRowHeight: false,
        rownumbers: true,
        pagination: true,
        pageSize: 15,
        pageList: [15, 30, 50],
        nowrap: true,
        loadMsg: '加载中,请稍后......',
        columns: [[{
            field: 'id',
            title: '主键',
            width: 80,
            hidden: true
        }, {
            field: 'rukudanhao',
            title: '入库单号',
            width: 130,
            align: 'center'
        }, {
            field: 'rukuleixing',
            title: '入库类型',
            width: 80,
            align: 'center',
            formatter: function (value, row, index) {
                if (value == 0) {
                    return "自产";
                } else if (value == 1) {
                    return "进货";
                } else if (value == 2) {
                    return "分销";
                } else if (value == 3) {
                    return "次品";
                }
            }
        }, {
            field: 'state',
            title: '状态',
            width: 90,
            align: 'center',
            styler: function (value, row, index) {
                if (row.state == 0) {
                    return 'color:red;'
                } else if (row.state == 1) {
                    return 'color:orange'
                } else {
                    return 'color:green'
                }
            },
            formatter: function (value, row, index) {
                if (value == 0) {
                    if (row.bohuirenName == null || row.bohuirenName == '') {
                        return '草稿'
                    } else {
                        return '草稿(驳回)'
                    }
                } else if (value == 1) {
                    return '待入库'
                } else if (value == 2) {
                    return '已入库'
                }
            }
        }, {
            field: 'gname',
            title: '供应商',
            width: 130,
            align: 'center'
        }, {
            field: 'phone',
            title: '供应商电话',
            width: 90,
            align: 'center'
        }, {
            field: 'zongshuliang',
            title: '总件数',
            width: 90,
            align: 'right'
        }, {
            field: 'zongjia',
            title: '总金额',
            width: 90,
            align: 'right',
            formatter: function (value, row, index) {
                return value.toFixed(2);
            }
        }, {
            field: 'zhidanshijian',
            title: '制单时间',
            width: 150,
            align: 'center'
        }, {
            field: 'zhidanrenName',
            title: '制单人',
            width: 80,
            align: 'center'
        }, {
            field: 'shenheshijian',
            title: '审核时间',
            width: 150,
            align: 'center'
        }, {
            field: 'shenherenName',
            title: '审核人',
            width: 80,
            align: 'center'
        }, {
            field: 'rukushijian',
            title: '入库时间',
            width: 150,
            align: 'center'
        }, {
            field: 'rukurenName',
            title: '入库人',
            width: 90,
            align: 'center'
        }, {
            field: 'bohuishijian',
            title: '驳回时间',
            width: 150,
            align: 'center'
        }, {
            field: 'bohuirenName',
            title: '驳回人',
            width: 80,
            align: 'center'
        }
        ]],
        onSelect: function (index, row) {
            $("#dgChildren").datagrid({
                url: path + '/ruku/childrenlist/id.do',
                queryParams: {
                    id: row.id,
                    fenlei: $(".fenlei:checked").val()
                }
            });
        },
        onBeforeLoad: function (param) {
        },
        onLoadSuccess: function (data) {
            if (data.total > 0) {
                $('#dg').datagrid("selectRow", 0);
            } else {
                $("#dgChildren").datagrid("loadData", {rows: []});
            }
        },
        onLoadError: function () {

        }
    });

    //加载子表
    function loadChildren() {
        var row = $('#dg').datagrid('getSelected');
        $("#dgChildren").datagrid({
            url: path + '/ruku/childrenlist/id.do',
            queryParams: {
                id: row.id,
                fenlei: $(".fenlei:checked").val()
            }
        });

    }

    /*入库下面表格*/
    $("#dgChildren").datagrid({
        method: 'GET',
        striped: true,
        rownumbers: false,
        singleSelect: true,
        toolbar: '#tbb',
        checkbox: false,
        fit: true,
        striped: true,
        fitColumns: false,
        autoRowHeight: false,
        rownumbers: true,
        pagination: false,
        nowrap: true,
        loadMsg: '加载中,请稍后......',
        columns: [[{
            field: 'id',
            title: '裁剪id',
            width: 80,
            hidden: true
        }, {
            field: 'product',
            title: '商品款号',
            width: 130,
            align: 'center'
        }, {
            field: 'anquanjibie',
            title: '安全级别',
            width: 130,
            align: 'center'
        }, {
            field: 'zhixingbiaozhun',
            title: '执行标准',
            width: 130,
            align: 'center'
        }, {
            field: 'mianliao',
            title: '面料',
            width: 130,
            align: 'center'
        }, {
            field: 'productName',
            title: '商品名称',
            width: 90,
            align: 'center'
        }, {
            field: 'color',
            title: '颜色',
            width: 90,
            align: 'center'
        }, {
            field: 'size',
            title: '尺码',
            width: 90,
            align: 'center'
        }, {
            field: 'pinpai',
            title: '品牌',
            width: 80,
            align: 'center'
        }, {
            field: 'style',
            title: '商品类型',
            width: 100,
            align: 'center'
        }, {
            field: 'chengbenjia',
            title: '成本价/￥',
            width: 120,
            align: 'right',
            formatter: function (value, row, index) {
                return value.toFixed(2)
            }
        }, {
            field: 'price',
            title: '铭牌价/￥',
            width: 120,
            align: 'right',
            formatter: function (value, row, index) {
                return value.toFixed(2)
            }
        }, {
            field: 'shuliang',
            title: '入库数量/件',
            width: 100,
            align: 'right'
        }, {
            field: 'zongjia',
            title: '总金额/￥',
            width: 120,
            align: 'right',
            formatter: function (value, row, index) {
                return value.toFixed(2)
            }
        }
        ]],
        onLoadSuccess: function (data) {
            var fenlei = $(".fenlei:checked").val();
            if (fenlei == 0) {
                $("#dgChildren").datagrid('hideColumn', 'color');
                $("#dgChildren").datagrid('hideColumn', 'size');
            } else if (fenlei == 1) {
                $("#dgChildren").datagrid('showColumn', 'color');
                $("#dgChildren").datagrid('hideColumn', 'size');
            } else {
                $("#dgChildren").datagrid('showColumn', 'color');
                $("#dgChildren").datagrid('showColumn', 'size');
            }
        }
    });


</script>

